package com.zb.internetSpider.gui.tree.listener;

import javax.annotation.Resource;
import javax.swing.event.TreeSelectionEvent;
import javax.swing.tree.TreePath;

import org.springframework.stereotype.Component;

import com.zb.internetSpider.gui.panel.AbstractSpiderContentPanel;
import com.zb.internetSpider.gui.tabsPanel.AbstractSpiderTabsPanel;
import com.zb.internetSpider.gui.tree.AbstractSpiderTree;
import com.zb.internetSpider.gui.tree.SpiderTreeNode;

@Component
public class DefaultSpiderTreeSelectionListener implements SpiderTreeSelectionListener {
	
	@Resource
	private AbstractSpiderTabsPanel spiderTabsPanel;
	
	@Resource(name = "menuManager")
	private AbstractSpiderContentPanel menuManagerPanel;
	
	@Resource(name = "urlManager")
	private AbstractSpiderContentPanel urlManagerPanel;
	
	

	@Override
	public void valueChanged(TreeSelectionEvent e) {
		// TODO Auto-generated method stub
		AbstractSpiderTree tree =   (AbstractSpiderTree) e.getSource();
		TreePath treePath = tree.getSelectionPath();
		SpiderTreeNode object = (SpiderTreeNode) treePath.getLastPathComponent();
		if(object.isLeaf()) {
			if(object.isMenuManager()){
				spiderTabsPanel.add(object.toString(), menuManagerPanel);
			}else if(object.isUrlManager()) {
				spiderTabsPanel.add(object.toString(), urlManagerPanel);
			}
		}
	}

}
